package com.example.serverlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

@WebServlet("/test02")
public class FreeMarker02 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置数据
        //布尔类型
        req.setAttribute("flag",true);
        //时间类型
        req.setAttribute("createDate",new Date());
        //数值类型
        req.setAttribute("age",18);
        req.setAttribute("num",10000);
        req.setAttribute("float",1.2);
        //字符串类型
        req.setAttribute("msg","hello");
        req.setAttribute("msg2","FreeMarker");
        //序列类型 (数组,list,map)
        String[] strings = new String[]{"1","2","3"};
        req.setAttribute("strings",strings);
        //请求转发
        req.getRequestDispatcher("template/test02.ftl").forward(req,resp);
        //resp.getWriter().write("123456");
    }
}
